﻿using System;
using FirstFloor.Documents.Annotations;
using FirstFloor.Documents.Controls.Commands;

namespace FirstFloor.Documents.Presentation.Commands
{
    /// <summary>
    /// Clears all text-based annotations from the current text selection
    /// </summary>
    public class ClearTextAnnotationsCommand
        : SelectionCommand
    {
        /// <summary>
        /// Gets a value indicating whether this command requires text to be selected.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this command requires selected text; otherwise, <c>false</c>.
        /// </value>
        protected override bool RequiresSelectedText
        {
            get { return true; }
        }

        /// <summary>
        /// Implements the actual command execution.
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        protected override void OnExecute(object parameter)
        {
            var service = AnnotationService.GetService(this.Selection.TextContainer);
            if (service != null && service.IsEnabled) {
                TextAnnotation.ClearTextAnnotationsForSelection(service);
                this.Selection.Unselect();
            }
        }
    }
}
